package com.zch.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zch.dao.ChatDeptUserMapper;
import com.zch.dao.model.ChatDeptUser;
import com.zch.dao.model.ChatDeptUserExample;

@Service
public class ChatDeptUserService {
	@Autowired
	private ChatDeptUserMapper chatDeptUserMapper;
	@Autowired
	private ChatMsgService chatMsgService;

	public int countByExample(ChatDeptUserExample example) {
		return this.chatDeptUserMapper.countByExample(example);
	}

	public ChatDeptUser selectByPrimaryKey(String id) {
		return this.chatDeptUserMapper.selectByPrimaryKey(id);
	}

	public List<ChatDeptUser> selectByExample(ChatDeptUserExample example) {
		return this.chatDeptUserMapper.selectByExample(example);
	}

	public int deleteByPrimaryKey(String id) {
		return this.chatDeptUserMapper.deleteByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(ChatDeptUser record) {
		return this.chatDeptUserMapper.updateByPrimaryKeySelective(record);
	}

	public int updateByPrimaryKey(ChatDeptUser record) {
		return this.chatDeptUserMapper.updateByPrimaryKey(record);
	}

	public int deleteByExample(ChatDeptUserExample example) {
		return this.chatDeptUserMapper.deleteByExample(example);
	}

	public int updateByExampleSelective(ChatDeptUser record, ChatDeptUserExample example) {
		return this.chatDeptUserMapper.updateByExampleSelective(record, example);
	}

	public int updateByExample(ChatDeptUser record, ChatDeptUserExample example) {
		return this.chatDeptUserMapper.updateByExample(record, example);
	}

	public int insert(ChatDeptUser record) {
		return this.chatDeptUserMapper.insert(record);
	}

	public int insertSelective(ChatDeptUser record) {
		return this.chatDeptUserMapper.insertSelective(record);
	}

	public int deleteByDeptNo(String code){
		if (code == null) return 0;
		ChatDeptUserExample example = new ChatDeptUserExample();
		example.createCriteria().andDeptNoEqualTo(code);
		List<ChatDeptUser> users = this.chatDeptUserMapper.selectByExample(example);
		for (ChatDeptUser user : users){
			chatMsgService.deleteByUser(user.getUserId());
		}
		return this.chatDeptUserMapper.deleteByExample(example);
	}
}
